<template>
	<view>
		<view class="navbar" style="padding: 20rpx;height: 180rpx;background-color: #fff;">
			<view class="title" style="font-size: 45rpx;font-weight: bold;color: #dd6161;text-align: center;">全部服务</view>
			<view class="search" style="width: 95%;margin: 20rpx auto;height: 64rpx;flex-shrink: 0;background-color: #f2f2f2;
			border: 2rpx solid #dd6161;border-radius: 50rpx;display: flex;flex-direction: row;justify-content: start;
			align-items: center;position: relative;">
				<u-icon name="search" style="margin-left: 20rpx;"></u-icon>
				<input type="text" placeholder="请输入关键字" v-model="value" style="margin-left: 20rpx;">
				<button class="bu" style="width: 120rpx;height: 95%;border-radius: 50rpx;background-color: #fa3534;
				position: absolute;right: 1rpx;top: 1rpx;" @click="submit">搜索</button>
			</view>
		</view>
		<view class="main">
			<scroll-view scroll-y="true" class="left">
				<view class="tab">
					<view class="tab-item center" v-for="(item,index) in tabList" @click="tabChange(index)" 
					:class="activeIndex === index ? 'active' : ''">{{item}}</view>
				</view>
			</scroll-view>
			<scroll-view scroll-y="true" class="right">
				<view class="cate">
					<view class="cate-item center" v-for="item in cateList">
						<image :src="$baseUrl + item.imgUrl"></image>
						<text>{{item.serviceName}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<u-popup mode="bottom" v-model="show" class="popup">
			<view class="cate">
				<view class="cate-item center" v-for="item in searchList">
					<image :src="$baseUrl + item.imgUrl"></image>
					<text>{{item.serviceName}}</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [],
				value: '',
				activeIndex: 0,
				cateList: [],
				show: false,
				searchList: []
			};
		},
		onLoad() {
			this.getTab()
			this.getCate()
		},
		methods:{
			getTab(){
				this.$request({
					url:'/prod-api/api/service/list'
				}).then(res => {
					console.log(res)
					this.tabList = new Set(res.rows.filter(item => item.serviceType !== null).map(item => item.serviceType))
					this.tabList = Array.from(this.tabList)
				})
			},
			tabChange(index){
				this.activeIndex = index
				this.getCate()
			},
			getCate(){
				this.$request({
					url: '/prod-api/api/service/list'
				}).then(res => {
					console.log(res)
					this.cateList = res.rows.filter(item => item.serviceType === this.tabList[this.activeIndex])
				})
			},
			submit(){
				this.show = true
				this.$request({
					url: '/prod-api/api/service/list'
				}).then(res => {
					console.log(res)
					this.searchList = res.rows.filter(item => item.serviceName.includes(this.value))
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		view{
			height: 100%;
			display: flex;
			flex-direction: column;
			.main{
				flex: 1;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				.left{
					height: 100%;
					width: 200rpx;
					background-color: #f7f7f7;
					.tab-item{
						padding: 20rpx;
						color: #666;
						height: 96rpx;
						position: relative;
						&:before{
							position: absolute;
							content: '';
							bottom: 0;
							left: 25%;
							width: 50%;
							border-top: 2rpx solid #e4e7ed;
						}
					}
					.active{
						color: #dd6161;
						font-weight: bold;
						font-size: 36rpx;
						&::after{
							position: absolute;
							content: '';
							width: 6rpx;
							height: 100%;
							background-color: #dd6161;
							left: 0;
							top: 0;
						}
					}
				}
				.right{
					flex: 1;
					.cate{
						display: flex;
						flex-wrap: wrap;
						flex-direction: row;
						justify-content: start;
						padding: 20rpx;
						height: fit-content;
						.cate-item{
							padding: 20rpx;
							width: 120rpx;
							height: fit-content;
							display: flex;
							flex-direction: column;
							image{
								width: 100rpx;
								height: 100rpx;
							}
							text{
								width: 120rpx;
								font-size: 26rpx;
								color: #666;
								margin-top: 10rpx;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
								text-align: center;
							}
							.icon{
								width: 100rpx;
								height: 100rpx;
								border: 4rpx solid #2979ff;
								color: #2979ff;
								border-radius: 50%;
							}
						}
					}
				}
			}  
			 .popup{
				 .cate{
				 	display: flex;
				 	flex-wrap: wrap;
				 	flex-direction: row;
				 	justify-content: start;
				 	padding: 20rpx;
				 	height: fit-content;
				 	.cate-item{
				 		padding: 20rpx;
				 		width: 120rpx;
				 		height: fit-content;
				 		display: flex;
				 		flex-direction: column;
				 		image{
				 			width: 100rpx;
				 			height: 100rpx;
				 		}
				 		text{
				 			width: 120rpx;
				 			font-size: 26rpx;
				 			color: #666;
				 			margin-top: 10rpx;
				 			white-space: nowrap;
				 			overflow: hidden;
				 			text-overflow: ellipsis;
				 			text-align: center;
				 		}
				 		.icon{
				 			width: 100rpx;
				 			height: 100rpx;
				 			border: 4rpx solid #2979ff;
				 			color: #2979ff;
				 			border-radius: 50%;
				 		}
				 	}
				 }
			 }
		}
	}
</style>
